public class errorCheck {
	
	
	public static String monthToNum(String month){
		String monthNum ="";
		
		switch(month){
		
		case "January": monthNum = "01";
						break;
		case "February": monthNum = "02";
						break;
		case "March": monthNum = "03";
						break;
		case "April": monthNum = "04";
						break;
		case "May": monthNum = "05";
						break;
		case "June": monthNum = "06";
						break;
		case "July": monthNum = "07";
						break;
		case "August": monthNum = "08";
						break;
		case "September": monthNum = "09";
						break;
		case "October": monthNum = "10";
						break;
		case "November": monthNum = "11";
						break;
		case "December": monthNum = "12";
						break;
		default: monthNum = "00"; //just for error checking
						break;
						
		}
		
		return monthNum;
	}
	
	public static String formatTime(String hour, String minute, String timeOfDay, boolean rtnHour){
		
		String finalTime ="";
		
		if(timeOfDay.equals("pm")){
			switch(hour){
			case "1": hour = "13";
					break;
			case "2": hour = "14";
					break;
			case "3": hour = "15";
					break;
			case "4": hour = "16";
					break;
			case "5": hour ="17";
					break;
			case "6": hour = "18";
					break;
			case "7": hour = "19";
					break;
			case "8": hour = "20";
					break;
			case "9": hour = "21";
					break;
			case "10": hour = "22";
					break;
			case "11": hour = "23";
					break;
			case "12": break;
			default: hour = "26"; //just for error checking again
					break;
			}
			
			
		}
		

		else if(timeOfDay.equals("am")){
			switch(hour){
			case "1": hour = "01";
					break;
			case "2": hour = "02";
					break;
			case "3": hour = "03";
					break;
			case "4": hour = "04";
					break;
			case "5": hour ="05";
					break;
			case "6": hour = "06";
					break;
			case "7": hour = "07";
					break;
			case "8": hour = "08";
					break;
			case "9": hour = "09";
					break;
			case "10": break;
			case "11": break;
			case "12": hour = "00"; 
				break;
			default: hour = "25"; //just for error checking again
					break;
			}
		}
		
		if(rtnHour == true) return hour;
		else{
		
		finalTime = "T"+hour+minute+"00Z";
		
		return finalTime;
		}
	}
	
	
	public static String formatDateTime(String year, String month, String day, String hour, String min, String timeOfDay){
		
		String finalDateTime = "";
		
		String finalMonth = monthToNum(month);
		
		switch(day){
		case "1": day = "01"; 
			break; 
		case "2": day = "02";
			break;
		case "3": day = "03";
			break;
		case "4": day = "04";
			break;
		case "5": day = "05";
			break;
		case "6": day = "06";
			break;
		case "7": day = "07";
			break;
		case "8": day = "08";
			break;
		case "9": day = "09";
			break;
		default: break;
		
		
		}
		
		String finalTime = formatTime(hour, min, timeOfDay, false);
		
		finalDateTime = year+finalMonth+day+finalTime;
		
		
		return finalDateTime;
	}
	
	
	public static boolean validateDate(String month, String day, String year){
		
		//change year to int so we can check for leap year
		int yearInt = Integer.parseInt(year);
		
		
		if(month.equals("September") || month.equals("April") || month.equals("June") || month.equals("November")){
			if(day.equals("31")){
				return false;
			}
		}
		else if( month.equals("February")){
				
			if(day.equals("31")|| day.equals("30")){
				return false;
			}
			else if((yearInt%400 != 0) ||(yearInt%4 != 0 && yearInt%100 == 0)){
				if(day.equals("29")){
					return false;
				}
					
			}
		}
		
		return true;
	}
	
	public static boolean validateEvent(String startMonth, String startDay, String startYear, String startHour, String startMin, String startTOD,
			String endMonth, String endDay, String endYear, String endHour, String endMin, String endTOD){
		
		//covert everything to ints for easier checking
		startMonth = monthToNum(startMonth);
		int startMonthInt = Integer.parseInt(startMonth);
		int startDayInt = Integer.parseInt(startDay);
		int startYearInt = Integer.parseInt(startYear);
		startHour = formatTime(startHour, startMin, startTOD, true);
		int startHourInt = Integer.parseInt(startHour);
		int startMinInt = Integer.parseInt(startMin);
		
		endMonth = monthToNum(endMonth);
		int endMonthInt = Integer.parseInt(endMonth);
		int endDayInt = Integer.parseInt(endDay);
		int endYearInt = Integer.parseInt(endYear);
		endHour = formatTime(endHour, endMin, endTOD, true);
		int endHourInt = Integer.parseInt(endHour);
		int endMinInt = Integer.parseInt(endMin);
		
		
		if(endYearInt - startYearInt <=0){
			if(endYearInt - startYearInt < 0) return false;
			else if(endMonthInt - startMonthInt <=0){
				if(endMonthInt - startMonthInt < 0) return false;
				else if(endDayInt - startDayInt <=0){
					if (endDayInt - startDayInt <0) return false;
					else if(endHourInt - startHourInt <=0){
						if(endHourInt - startHourInt <0) return false;
						else if(endMinInt - startMinInt <=0)return false;
						
					}
				}
			}
		}

		return true;
	}
	
	
}
	

